class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def splitBST(self, root, target):
        """
        :type root: TreeNode
        :type target: int
        :rtype: List[TreeNode]
        """
        left_root = None
        right_root = None
        node = root
        while node:
            if node.val < target:
                if not left_root:
                    left_root = node
                    left_node = left_root
                    node = node.right
                    if right_root:
                        right_node.left = None
                else:
                    left_node.right = node
                    left_node = node
                    if right_root:
                        right_node.left = None
            else:
                if node.val > target:
                    if not right_root:
                        right_root = node
                        right_node = node
                        node = node.left
                        if left_root:
                            left_node.right = None
                    else:
                        right_node.left = node
                        right_node = right_node.left
                        node = node.left
                        if left_root:
                            left_node.right = None
                else:
                    if left_root:
                        left_node.right = node
                        if right_root:
                            right_node.left = node.right
                            node.right = None
                        else:
                            right_root = node.right
                            node.right = None
                    else:
                        left_root = node
                        if right_root:
                            right_node.left = node.right
                            node.right = None
                        else:
                            right_root = node.right
                            node.right = None
                    break

        return left_root, right_root


